home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / infoserv / gopher / Gopher_Conference_94 / Papers / GopherSQL.Z / GopherSQL
Encoding:
Text File  |  1994-04-20  |  17.3 KB  |  674 lines

  1. A Gopher Interface to 
  2. Relational Databases
  3.  
  4. Paul Lindner
  5.  
  6.  
  7.  
  8. April 18, 1994
  9.  
  10. At the University of Minnesota we've developed software 
  11. that allows a Gopher user to access the data in an SQL 
  12. database. This piece of software is called a gateway. In 
  13. general a gateway translates the operations and data of one 
  14. system into operations supported by a different, incompat-
  15. ible system.
  16.  
  17. Our gateway translates Gopher operations into SQL state-
  18. ments and the SQL results are translated into Gopher data. 
  19. The gateway method of accessing the database simplifies 
  20. the allowable operations to a limited, yet useful subset of 
  21. the allowable SQL queries.
  22.  
  23. We've been using this software for some time now. We 
  24. demonstrate some sample databases that the gateway is 
  25. currently using and draw some conclusions about the soft-
  26. ware.
  27.  
  28. 1.0    Introduction
  29.  
  30. The Internet Gopher is a suite of software that allows for 
  31. easy access to network-based information. Initially devel-
  32. oped at the University of Minnesota in early 1991, it has 
  33. spread to over 1600 sites worldwide as of July 1993.
  34.  
  35. Gopher is a client-server system that can be used to build a 
  36. Campus Wide Information System (CWIS). Clients, 
  37. which browse and search information are available for 
  38. most major platforms (Macintosh, DOS, Windows, Unix, 
  39. VMS, MVS, VM/CMS, OS/2). Servers, which translate 
  40. and publish information, are also available for all of the 
  41. platforms mentioned above.
  42.  
  43. This client-server architecture uses the Internet Gopher 
  44. Protocol [Gopher91, RFC1436]. The Gopher protocol has 
  45. been described as "brutally simple." It is based on a web/
  46. tree metaphor of files and directories. Its basic primitives 
  47. are a list directory transaction, a retrieve file transaction 
  48. and a search for directory entries transaction.
  49.  
  50. Given this design it isn't surprising to see that most imple-
  51. mentations of Gopher Servers map a filesystem to Gopher-
  52. Space. An example of a file system hierarchy would be the 
  53. registry of all gopher servers. The registry is divided into a 
  54. number of directories based on geography. At the top level 
  55. is the directory of continents, then there are subdirectories 
  56. of countries for each continent, then a state or province 
  57. subdirectory. After all of this digging you will find the 
  58. information you want.
  59.  
  60. For most data this approach works rather well; a good por-
  61. tion of the data people want to publish are in files located 
  62. in directories. However there is a whole class of data that 
  63. doesn't fit into a file system that easily: databases, espe-
  64. cially relational databases. Databases are better than files 
  65. for a number of reasons including data consistency and 
  66. multiple indexes [Lindner93].
  67.  
  68. To handle this type of data we've developed a gateway 
  69. that translates Gopher requests into SQL (Structured 
  70. Query Language) statements and SQL results into Gopher 
  71. data. This gateway allows a Gopher user to look at the data 
  72. inside of SQL tables using the gopher browse/search met-
  73. aphor. It simplifies the allowable operations on the data-
  74. base to a limited, yet useful subset of the allowable SQL 
  75. queries.
  76.  
  77. Since most of our campus knows how to use Gopher 
  78. already, training time is minimized. Also, Gopher is cost-
  79. effective: commercial software packages usually require 
  80. you to spend over 200 dollars per machine for software to 
  81. access the SQL database. This software may be useful for 
  82. some, but for most people on our campus the Gopher 
  83. interface is sufficient.
  84.  
  85. 2.0    Features of the SQL Gateway
  86.  
  87. The SQL gateway allows people using a Gopher Client to 
  88. access the data contained in an SQL database without hav-
  89. ing to know SQL. The gateway is the only portion of code 
  90. that needs to know any SQL. The clients can be used as is 
  91. with the gateway, no modifications for the clients are 
  92. needed.
  93.  
  94. The SQL gateway accepts gopher requests and translates 
  95. them into SQL statements that get passed via TCP to 
  96. either a Sybase or Oracle database.
  97.  
  98. The SQL gateway allows the Gopher Client to:
  99.  
  100. ╖    View the tables of a database as a Gopher directory 
  101.  
  102. ╖    View the columns of a given table as a Gopher direc-
  103. tory 
  104.  
  105. ╖    View the contents of a column as a Gopher directory 
  106.  
  107. ╖    See how many records will result from a query before 
  108. viewing records 
  109.  
  110. ╖    View records as formatted text. 
  111.  
  112. ╖    View/import records as tab-separated-values 
  113.  
  114. ╖    Add records to a table. o Search the table by filling out 
  115. a Gopher+ form.
  116.  
  117. The server/gateway administrator has control over the 
  118. configuration. The administrator can give column/table 
  119. names more descriptive titles, and can link columns 
  120. together to make a subdirectories via implicit joins.
  121.  
  122. 3.0    Semantics of a Gateway, or how a 
  123. Gateway works
  124.  
  125. A gateway is a simple thing. It translates commands and 
  126. data from one format to another. Gopher has long used 
  127. gateways to lash together disparate information systems 
  128. such as USENET, Archie, X.500, FTP, WAIS and others. 
  129. In fact Gopher has been referred to as the "Duct Tape of 
  130. the Internet" by some.
  131.  
  132. The SQL gateway translates Gopher Operations into SQL 
  133. statements. We do lose functionality when doing this how-
  134. ever. The large set of possible operations in SQL would be 
  135. hard to present using the very simple Gopher protocol 
  136. operations. (It might be possible with a large enough 
  137. directory tree though..)
  138.  
  139. 3.1    Semantics of the Gopher Protocol
  140.  
  141. The Gopher Protocol is very simple information retrieval 
  142. tool based on the client-server model. It uses three basic 
  143. transactions/commands.
  144.  
  145. ╖    Directory listing 
  146.  
  147. ╖    File retrieval 
  148.  
  149. ╖    Search and return a directory listing
  150.  
  151. These simple directives are quite powerful, over 1500 sites 
  152. over the world now use the base Gopher protocol. In the 
  153. Spring of 1992 we proposed a suite of upward/downward 
  154. compatible extensions to the Gopher protocol called 
  155. "Gopher+". Gopher+ adds the following features to the 
  156. base gopher protocol:
  157.  
  158. ╖    Forms input 
  159.  
  160. ╖    Multiple alternate document representations (VIEWS) 
  161.  
  162. ╖    Metainformation about an object (administrator, size, 
  163. etc..)
  164.  
  165. The SQL Gateway uses the Gopher+ protocol for some of 
  166. it's features: optional tab-separated documents and solici-
  167. tation of searches via a form.
  168.  
  169. 3.2    Semantics of the Structured Query 
  170. Langauage (SQL).
  171.  
  172. SQL is a full featured database access language. Some of 
  173. the more common operations supported by SQL are:
  174.  
  175. ╖    o "Select"ing records from a table 
  176.  
  177. ╖    "Insert"ing records into a table 
  178.  
  179. ╖    Searching/querying multiple tables for information 
  180.  
  181. ╖    Ordering of results 
  182.  
  183. ╖    Grouping of results 
  184.  
  185. ╖    Creation/deletion of tables or views 
  186.  
  187. ╖    Computations on data (aggregate values)
  188.  
  189. In addition, most SQL databases support the concept of 
  190. the Data Dictionary. The data dictionary is a database that 
  191. describes the contents of other databases, tables and col-
  192. umns. Different vendors have different data dictionary for-
  193. mats, this can cause some problems..
  194.  
  195. 3.3    Semantics of the SQL Gateway
  196.  
  197. The SQL gateway understands a small limited number of 
  198. commands. These commands perform the mapping 
  199. between Gopher operations and SQL statements. The 
  200. gateway understands the following commands:
  201.  
  202. ╖    Get a listing of all tables 
  203.  
  204. ╖    Get a listing of columns in specific tables 
  205.  
  206. ╖    Get a list of distinct values in a specific column
  207.  
  208. ╖    Display records given a search 
  209.  
  210. ╖    Insert a new record
  211.  
  212. ╖    Delete records
  213.  
  214. 3.4    Mapping Operations and Data Between 
  215. Different systems
  216.  
  217. Any gateway maps between multiple sets of available 
  218. operations and data formats. The Gopher to SQL gateway 
  219. maps gopher operations (selecting a directory, choosing a 
  220. file) into it's internal command set ("tables" command, 
  221. "get" command) and then into SQL (select tables from 
  222. dictionary, select * from tablename). 
  223.  
  224. It then translates the results received from the SQL query 
  225. back down the chain. For instance the results of a "select 
  226. tablename from dictionary" would generate intermediate 
  227. gateway operations "columns tablename". These com-
  228. mands would finally be translated into the gopher direc-
  229. tory format and sent to the client.
  230.  
  231. The following table summarizes the equivalency between 
  232. the different command sets.
  233.  
  234. Gateway 
  235. Command
  236.  
  237. Gopher 
  238. Data
  239.  
  240. SQL
  241.  
  242. Statement
  243.  
  244. tables
  245.  
  246. Directory
  247.  
  248. select tablename from 
  249. dictionary
  250.  
  251. columns <table>
  252.  
  253. Directory
  254.  
  255. select columnname 
  256. from dictionary where 
  257. tablename=<table>
  258.  
  259. list <table.col-
  260. umn>
  261.  
  262. Directory
  263.  
  264. select distinct table.col-
  265. umn from table
  266.  
  267. get <table.col-
  268. umn> <query>
  269.  
  270. Text
  271.  
  272. select * from table 
  273. where query
  274.  
  275. 4.0    Sample Databases
  276.  
  277. We have been using this gateway to provide access to a 
  278. number of databases at the University of Minnesota. We 
  279. detail the setup of some of them here.
  280.  
  281. 4.1    The Sample "pubs2" database
  282.  
  283. The Sybase Database comes with a sample database of 
  284. authors, titles, publishes and stores called "pubs2". This 
  285. database demonstrates a number of features, including 1:N 
  286. and N:N relations.
  287.  
  288. For this database we set up a few sample queries at the 
  289. top-most level and added an entry to view the database in 
  290. it's raw format: A tree listing of the gatewayed access to 
  291. the database is below. A complete listing would be quite 
  292. huge, only portions of the tree are shown below.
  293.  
  294. Authors by City/
  295.  
  296.   Ann Arbor
  297.  
  298.   Berkeley (2)
  299.  
  300.   Cornvalis
  301.  
  302.   ...
  303.  
  304. Authors by Name/
  305.  
  306.   Bennet
  307.  
  308.   Blochet-Halls
  309.  
  310.   Carson
  311.  
  312.   ...
  313.  
  314. Titles by Name/
  315.  
  316.   But is it User Friendly?
  317.  
  318.   Computer Phobic and Non-Phobic Individuals: 
  319. Behavior Variations
  320.  
  321.   Cooking with Computers: Surreptitious Balance 
  322. Sheets
  323.  
  324.   ..
  325.  
  326. Titles by Publication Date/
  327.  
  328.   Jun 12 1985 12:00:00:000AM
  329.  
  330.   Jun 18 1985 12:00:00:000AM
  331.  
  332.   Jun 30 1985 12:00:00:000AM
  333.  
  334. Raw DB access /
  335.  
  336.   Author Pictures/
  337.  
  338.   Author List/
  339.  
  340.     All Records (23).
  341.  
  342.     Add a Record
  343.  
  344.     Author ID Number/
  345.  
  346.     Author Last Name/
  347.  
  348.     Author First Name/
  349.  
  350.     Phone/
  351.  
  352.     Address/
  353.  
  354.     City/
  355.  
  356.     State/
  357.  
  358.     Country/
  359.  
  360.     Postalcode/
  361.  
  362.     Multiple Field Search, sorted by Author ID Num-
  363. ber
  364.  
  365.     Multiple Field Search, sorted by Author Last 
  366. Name
  367.  
  368.     ...
  369.  
  370.   Author Descriptions/
  371.  
  372.   Discounts/
  373.  
  374.   Publishers/
  375.  
  376. Roysched/
  377.  
  378.   Sales/
  379.  
  380.   Salesdetail/
  381.  
  382.   Stores/
  383.  
  384.   Author--Title Join Table (Not Interesting...)/
  385.  
  386.   Book Titles/
  387.  
  388.   Titleview/
  389.  
  390.  
  391.  
  392. 4.2    The Financial Detail Reporting Database
  393.  
  394. This database is considerably more complex than the 
  395. PUBS2 database. This database contains all the financial 
  396. transactions of the University of Minnesota. This is one 
  397. _big_ database! The monthly transactions are in the four 
  398. to five hundred thousand range!
  399.  
  400. We set up a menu system to do specific queries to this 
  401. database. This keeps users from running inefficiently 
  402. formed queries. The menu structure was created on a Unix 
  403. machine running the Unix Gopher Server software. This 
  404. server also provides explanations about what all the differ-
  405. ent code numbers mean. All of the SQL gateway function-
  406. ality is still in the SQL Gateway. The Unix server makes 
  407. "links" to the SQL Gateway, using it's functionality at spe-
  408. cific points in the hierarchy.
  409.  
  410. This is the tree listing of the directory structure of the 
  411. Financial Reporting Database System.
  412.  
  413. About The Financial Reporting Database
  414.  
  415.   Terms used in the Financial Reporting Database
  416.  
  417.   Areas and Organizations/
  418.  
  419.     List of Areas and Organizations by Area Name
  420.  
  421.       COMPUTER AND INFO SYSTEMS
  422.  
  423.       COMPUTER SCIENCE
  424.  
  425.       ...
  426.  
  427.     List of Areas and Organizations by Function/
  428.  
  429.        
  430.  
  431.   Balance Sheets/
  432.  
  433.     List of Balance Sheets by Area Number/
  434.  
  435.       0510
  436.  
  437.       0620
  438.  
  439.       ...
  440.  
  441.   This Months Transactions/
  442.  
  443.     Search Transaction Table (form)
  444.  
  445.     Transactions by Fund Number
  446.  
  447.  
  448.  
  449. 5.0    Technical Details
  450.  
  451. It isn't too difficult to set up a Gopher to SQL database. 
  452. This section gives an overview of how the software is con-
  453. structed.
  454.  
  455. To run the server you will need some special software.
  456.  
  457. If using Sybase:
  458.  
  459. You will need a machine with the Sybase client librar-
  460. ies (usually stored in /usr/sybase) and a special version 
  461. of perl called sybperl [Peppler92].
  462.  
  463. If using Oracle:
  464.  
  465. You will need a machine with the Oracle client librar-
  466. ies and a special version of perl called oraperl 
  467. [Stock93].
  468.  
  469. Each of these uses specific "glue" routines to implement 
  470. database specific features (connecting, data dictionary, 
  471. etc.). Thus it is fairly easy to extend the gateway to deal 
  472. with other database vendors.
  473.  
  474. 5.1    Command line options understood by the 
  475. gateway
  476.  
  477. Major parameters are set via command line switches. The 
  478. following table summarizes them:
  479.  
  480.  
  481.  
  482. Option
  483.  
  484. Description
  485.  
  486. -h
  487.  
  488. Hostname of the gateway
  489.  
  490. -p
  491.  
  492. Port number of the gateway
  493.  
  494. -T
  495.  
  496. Database Type (oracle, sybase, etc.)
  497.  
  498. -S
  499.  
  500. SQL Server to connect to.
  501.  
  502. -D
  503.  
  504. Database to use
  505.  
  506. -U
  507.  
  508. Username to use
  509.  
  510. -P
  511.  
  512. Password to use
  513.  
  514. 5.2    Selectors understood by the Gateway...
  515.  
  516. The gateway implements a small internal command set. 
  517. The following summarizes this small command language.
  518.  
  519. ╖    tables [<search>]
  520.  
  521. This command uses the data dictionary to make a 
  522. gopher directory list of the different tables in the data-
  523. base. This is most useful for allowing raw database 
  524. access. This command generates "columns" com-
  525. mands that the client will execute.
  526.  
  527. An optional search item will restrict the tables to match 
  528. the search term.
  529.  
  530. ╖    columns <tablename> [<search>]
  531.  
  532. This command uses the data dictionary to make a 
  533. gopher directory list of the columns in <tablename>. 
  534. This command generates "list" commands for each 
  535. column in the table. It also generates a "get" command 
  536. that will retrieve all the records of a table as text.
  537.  
  538. After the column names are presented, a list of search 
  539. items is presented. If the client is using Gopher+ it gets 
  540. a list of forms.
  541.  
  542. If the user can write to the table an "insert" item for 
  543. adding an item to the database is added to the menu.
  544.  
  545. An optional search item will restrict the tables to match 
  546. the search term.
  547.  
  548. ╖    list <tablename.columnname> [<fromtables> 
  549. [<query>]] [<search>]
  550.  
  551. This command generates a listing of the unique items 
  552. in the given table and column.
  553.  
  554. This command can be part of a multiple series of que-
  555. ries by specifying an optional list of tables to choose 
  556. from and an query. This gets translated into SQL that 
  557. looks like this:
  558.  
  559.  select ..... from <fromtables> where <query>
  560.  
  561. An optional search can search for specific titles in the 
  562. specified table and column.
  563.  
  564. An optional form may be specfied if this command is 
  565. used as *asklist*
  566.  
  567. ╖    get <tablename.columnname> <fromtables> <query>
  568.  
  569. This command actually retrieves a record from the 
  570. database as a textual item. The default is to print out 
  571. each column name, a colon and the data contained in it. 
  572. Multiple records are separated with a line of "dashes".
  573.  
  574. Optionally one may define a module for a specific 
  575. table. This module is a file containing perl code that 
  576. can do sub-queries and fancy reformatting of the data 
  577. into any format you desire.
  578.  
  579. ╖    insert <tablename>
  580.  
  581. This command inserts a new record into the specified 
  582. table. The values for the table come from the ASK 
  583. Block.
  584.  
  585. 5.3    Files used by the Gateway
  586.  
  587. The gateway uses a number of configuration files to con-
  588. trol and enhance the way it operates. These files and their 
  589. format are summarized below:
  590.  
  591. ╖    namelist.<databasename>
  592.  
  593. This file is basically a local table of mappings between 
  594. column/table names and Gopher Title Names. The for-
  595. mat is:
  596.  
  597. <table>:<Gopher Table Name> <table.col-
  598. umn>:<Gopher Column Name> <.Col-
  599. umn>:<Gopher Column Name>
  600.  
  601. Eventually this table could be kept on the database 
  602. itself, eliminating the need for a local filename.
  603.  
  604. ╖    jointable.<databasename>
  605.  
  606. This file allows you to link together two tables, allow-
  607. ing you to do implicit joins between the two tables.
  608.  
  609. The format is as follows:
  610.  
  611. <source-table.column>:<target-table.col-
  612. umn>:<additional_tables>:<join query>
  613.  
  614. ╖    <tablename>.module
  615.  
  616. Files in this format can override the default record dis-
  617. play routines. Thus, if you want to join data in with the 
  618. text, this is one way to do it.
  619.  
  620. For instance, in the PUBS2 Database the author table 
  621. display record is overridden so we can display the 
  622. address correctly, and also join in the au_blurbs table.
  623.  
  624. 6.0    Conclusions:
  625.  
  626. In the short time we've been operating the gateway we've 
  627. noticed many things. First, most people seem to like not 
  628. having to learn SQL to get their data. They like the ease of 
  629. use of making an SQL query with the click of the mouse.
  630.  
  631. The gateway allows us to control access to our SQL server 
  632. in more sophisticated ways. We've set up transactions that 
  633. we know won't take forever. This is a pitfall if you're 
  634. using SQL directly. We are enjoying some vendor inde-
  635. pendence now, since the gateway sits at a layer above the 
  636. RDBMS. We could migrate our data to another system if 
  637. we wish.
  638.  
  639. In short we've been very pleased with this software and 
  640. will continue to enhance, modify and support it.
  641.  
  642. 7.0     References:
  643.  
  644. 1.    [Gopher91] University of Minnesota Gopher Team, 
  645. (gopher@boombox.micro.umn.edu) The Internet 
  646. Gopher Protocol {URL=gopher://boom-
  647. box.micro.umn.edu:70/0/0/gopher/gopher_protocol/}
  648.  
  649. 2.    [Gopher92] University of Minnesota Gopher Team, 
  650. (gopher@boombox.micro.umn.edu) Gopher+, pro-
  651. posed enhancements to the internet Gopher protocol 
  652. {URL=gopher://boombox.micro.umn.edu:70/0/0/
  653. gopher/gopher_protocol/}
  654.  
  655. 3.    [RFC1436] University of Minnesota Gopher Team, 
  656. (gopher@boombox.micro.umn.edu) The Internet 
  657. Gopher Protocol
  658.  
  659. 4.    [Lindner93] Lindner, P. (lindner@boom-
  660. box.micro.umn.edu), Gopher and Relational Data-
  661. bases, an Interface to Metalbase. Proceedings of 
  662. GopherCon `93 
  663.  
  664. 5.    [Peppler92] Michael Peppler (mpeppler@itf.ch), syb-
  665. perl - Sybase DB-library extensions to Perl,. USENET 
  666. posting in comp.sources.misc {URL=ftp://ftp.uu.net/
  667. usenet/comp.sources.misc/volume30/sybperl}
  668.  
  669. 6.    [Stock93] Kevin Stock (kstock@encore.com), Orap-
  670. erl-v2 - Extensions to Perl to access Oracle databases. 
  671. USENET posting in comp.sources.misc {URL=ftp://
  672. ftp.uu.net/usenet/comp.sources.misc/volume38/orap-
  673. erl-v2/}
  674.